package com.example.xm.ui.discover.fragment;

import android.widget.LinearLayout;

import androidx.recyclerview.widget.DividerItemDecoration;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.example.xm.R;
import com.example.xm.adapter.DiscoverAdapter.DiscoverPagerAdapter;
import com.example.xm.base.BaseFragment;
import com.example.xm.bean.DiscoverBean.DiscoverPagerBean;
import com.example.xm.bean.DiscoverBean.DiscoverPaoZhiBean;
import com.example.xm.bean.DiscoverBean.DiscoverReMenBean;
import com.example.xm.interfaces.discover.IDiscover;
import com.example.xm.presenter.discover.DiscoverPresenter;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

public class ReDianFragment extends BaseFragment<IDiscover.Presenter> implements IDiscover.View {
    @BindView(R.id.rlv_redian)
    RecyclerView rlvRedian;
    private ArrayList<DiscoverPagerBean.DataBean.ListBean> list;
    private DiscoverPagerAdapter discoverPagerAdapter;
    private int id;

    public ReDianFragment(int id) {
        this.id = id;
    }

    @Override
    protected IDiscover.Presenter initPresenter() {
        return new DiscoverPresenter();
    }

    @Override
    protected int getLayout() {
        return R.layout.fragment_discover_redian;
    }

    @Override
    protected void initView() {
        list = new ArrayList<>();
        discoverPagerAdapter = new DiscoverPagerAdapter(getActivity(), list);
        rlvRedian.setLayoutManager(new LinearLayoutManager(getActivity()));
        rlvRedian.addItemDecoration(new DividerItemDecoration(getActivity(), LinearLayout.VERTICAL));
        rlvRedian.setAdapter(discoverPagerAdapter);
    }

    @Override
    protected void initData() {
        mPresenter.getPager(id);
    }

    @Override
    protected void initListener() {

    }

    @Override
    public void getReMenResult(DiscoverReMenBean result) {

    }

    @Override
    public void getPaoZhiResult(DiscoverPaoZhiBean result) {

    }

    @Override
    public void getPagerResult(DiscoverPagerBean result) {
        if (result.getStatus().getStatusCode() == 100) {
            List<DiscoverPagerBean.DataBean.ListBean> list = result.getData().getList();
            this.list.addAll(list);
            discoverPagerAdapter.notifyDataSetChanged();
        }
    }

    @Override
    public void showTips(String tips) {

    }

    @Override
    public void showLoading(int visble) {

    }
}
